package com.wondersgroup.insurance.dnuilearn.views.svg_map;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Region;

/**
 * Created by Administrator on 2017/6/1.
 */

public class ItemPath {
    public Path path;
    public int color = Color.WHITE;

    public boolean isSelect = false;

    public void draw(Canvas canvas, Paint StrokePaint, Paint fillPaint) {


//        canvas.drawPath(path, StrokePaint);


        if (isSelect) {
            fillPaint.setStrokeWidth(20);
            fillPaint.setColor(Color.BLACK);
            fillPaint.setStyle(Paint.Style.FILL);
            fillPaint.setShadowLayer(10, 0, 0, Color.parseColor("#FF4081"));//Color.parseColor("#FF4081")
            canvas.drawPath(path, fillPaint);
        } else {
            fillPaint.clearShadowLayer();
        }

        fillPaint.setColor(color);
        fillPaint.setStrokeWidth(4);
        fillPaint.setStyle(Paint.Style.FILL);
        canvas.drawPath(path, fillPaint);
        canvas.drawPath(path, StrokePaint);

    }

    public boolean isSelect(int x, int y) {
        //构造一个区域对象，左闭右开的。
        RectF r = new RectF();
        //计算控制点的边界
        path.computeBounds(r, true);
        //设置区域路径和剪辑描述的区域
        Region region = new Region();
        region.setPath(path, new Region((int) r.left, (int) r.top, (int) r.right, (int) r.bottom));
        return region.contains(x, y);
    }
}
